package cloudoer.blog.controller;

import cloudoer.blog.base.BaseController;
import cloudoer.blog.entity.Type;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/type")
public class TypeController extends BaseController {
    private static Logger logger = Logger.getLogger(TypeController.class);

    @RequestMapping("/index")
    public String index(){
        return "admin/type/index";
    }

    @RequestMapping("/addUI")
    public String addUI(){
        return "admin/type/add";
    }
    @RequestMapping("/updateUI")
    public String updateUI(){
        return "admin/type/update";
    }

    @RequestMapping("/getAll")
    @ResponseBody
    public Map<String, Object> getAll (){
        List<Type> list = typeService.getAll();
        return getMap(list);
    }

    @RequestMapping("/add")
    @ResponseBody
    public Map<String, Object> add(Type type){
        typeService.add(type);
        return success("添加成功");
    }

    @RequestMapping("/update")
    @ResponseBody
    public Map<String, Object> update (Type type){
        typeService.update(type);
        return success("修改成功");
    }
    @RequestMapping("/delete")
    @ResponseBody
    public Map<String, Object> delete (String id){
        typeService.delete(id);
        return success("删除成功");
    }
}
